import Vue from "vue";
import Vuex from "vuex";
import user from "./modules/user";
import supplier from "./modules/supplier";
import shoppingCart from "./modules/shoppingCart";
import order from "./modules/order";
import goods from "./modules/goods";
Vue.use(Vuex);

const store = new Vuex.Store({
  strict: true, // 严格模式
  state: {
    loginPerson: null, // 存储当前登录用户信息
    loginTime: null, // 存储登录时间
  },
  getters: {},
  mutations: {
    // 保存登录用户信息
    SET_LOGIN_PERSON(state, person) {
      state.loginPerson = person;
      state.loginTime = new Date().toDateString(); // 记录登录时间
      localStorage.setItem("loginTime", JSON.stringify(state.loginTime)); // 将登录时间存储到 localStorage
      localStorage.setItem("loginPerson", JSON.stringify(person)); // 将用户信息存储到 localStorage
    },
  },
  actions: {},
  modules: {
    // 模块化
    user,
    supplier,
    shoppingCart,
    order,
    goods,
  },
});
export default store;
